package com.cy.pj.common.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author Cx
 * @stage secondStageOfWeb
 * @creat 2020-11-12 15:47
 */
@Aspect
@Component
public class SysTimeAspect {

    @Pointcut("bean(categoryServiceImpl)")
    public void doTime() {
    }

    @Before("doTime()")
    public void doBefore() {
        System.out.println("@Before");
    }

    @After("doTime()")
    public void doAfter() {
        System.out.println("@After");
    }

    @AfterReturning("doTime()")
    public void doAfterReturning() {
        System.out.println("@AfterReturning");
    }

    @AfterThrowing("doTime()")
    public void doAfterThrowing() {
        System.out.println("@AfterThrowing");
    }

    @Around("doTime()")
    public Object doCacheAround(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println(" @Around.before");
        try {
            Object result = joinPoint.proceed();
            System.out.println(" @Around.after");
            return result;
        } catch (Throwable e) {
            System.out.println(" @Around.exception");
            throw e;
        }

    }

}
